import React, { Component } from 'react'

export default class Tab extends Component {

  add = (e) => {
    if (e.type == "keydown") {
      if (e.keyCode == 13) {
        this.props.addTodos(e.target.value)
        e.target.value = ''
      }
    }
    if (e.type == 'click') {
      this.props.addTodos(this.input.value)
      this.input.value = ''
    }
  }
  render () {
    return (
      <div>
        <input type="text" placeholder='请输入' onKeyDown={this.add} ref={el => this.input = el} />
        <button onClick={this.add}>添加</button>
      </div>
    )
  }
}
